package cn.net.shuxing.yifu.common.bean;

import java.lang.reflect.Method;
import java.time.LocalDateTime;

public abstract class BaseBean {

    public BaseBean()
    {
        resetCreateTimeAndUpdateTime();
    }

    public void resetCreateTimeAndUpdateTime()
    {
        resetCreateTime();
        resetUpdateTime();
    }

    public void resetCreateTime()
    {
        try{
            Class<? extends BaseBean> beanClass = this.getClass();
            Method setCreateTime = beanClass.getMethod("setCreateTime", LocalDateTime.class);

            LocalDateTime localDateTime = LocalDateTime.now();
            setCreateTime.invoke(this,localDateTime);
        }catch(Exception e){

        }
    }

    public void resetUpdateTime()
    {
        try{
            Class<? extends BaseBean> beanClass = this.getClass();
            Method setUpdateTime = beanClass.getMethod("setUpdateTime", LocalDateTime.class);

            LocalDateTime localDateTime = LocalDateTime.now();
            setUpdateTime.invoke(this,localDateTime);

        }catch(Exception e){

        }
    }

    public void clearCreateTimeAndUpdateTime()
    {
        try{
            Class<? extends BaseBean> beanClass = this.getClass();
            Method setCreateTime = beanClass.getMethod("setCreateTime", LocalDateTime.class);
            Method setUpdateTime = beanClass.getMethod("setUpdateTime", LocalDateTime.class);

            LocalDateTime localDateTime = null;
            setCreateTime.invoke(this,localDateTime);
            setUpdateTime.invoke(this,localDateTime);

        }catch(Exception e){

        }
    }

    public void setDeleted(Integer i)
    {

    }

    public LocalDateTime getCreateTime()
    {
        return null;
    }

    public Integer getDeleted() {
        return 0;
    }
}
